package com.gdufe.firesafe.model.dto;

import cn.hutool.core.bean.BeanUtil;
import com.gdufe.firesafe.model.entity.DeviceEntity;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 消防设备新增请求DTO
 */
@Data
public class DeviceDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    private Integer id;
    /**
     * 所属房屋，[buildingId,floorId,houseId]
     */
    private List<Integer> selectedHouse;
    /**
     * 是否可用
     */
    private Boolean available;
    /**
     * 设备类型（1-灭火器，2-烟雾探测器）
     */
    private Integer type;
    /**
     * 设备型号
     */
    private String model;
    /**
     * 生产厂商
     */
    private String manufacturer;
    /**
     * 购买日期
     */
//	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date purchaseDate;
    /**
     * 设备到期时间
     */
    private Date expireDate;
    /**
     * 备注
     */
    private String note;

    public static DeviceDTO entityToDTO(DeviceEntity device) {
        DeviceDTO deviceDTO = BeanUtil.copyProperties(device, DeviceDTO.class);
        List<Integer> selectedHouse = new ArrayList<>();
        selectedHouse.add(device.getBuildingId());
        selectedHouse.add(device.getFloorId());
        selectedHouse.add(device.getHouseId());
        deviceDTO.setSelectedHouse(selectedHouse);
        return deviceDTO;
    }

    public DeviceEntity toEntity() {
        DeviceEntity device = BeanUtil.copyProperties(this, DeviceEntity.class);
        device.setBuildingId(this.getSelectedHouse().get(0));
        device.setFloorId(this.getSelectedHouse().get(1));
        device.setHouseId(this.getSelectedHouse().get(2));
        return device;
    }
}
